package com.sugon.quartz;

import java.time.LocalDateTime;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.quartz.SchedulerException;

import lombok.Data;

/**
 * @desc:
 * @author: luoy
 * @date: 2021-12-02 16:14
 */
@Data
//@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class HelloJob  implements Job {



    String num;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();

        JobDataMap triggerMap = context.getTrigger().getJobDataMap();

        Object sv = null;
        try {
            Thread.sleep(3000);
            sv = context.getScheduler().getContext().get("skey");
        } catch (SchedulerException | InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(sv);
//        System.out.println("num:"+context.getJobDetail().getJobDataMap().getString("num"));
//        System.out.println("num:"+triggerMap.getString("num"));


        // merge map

        JobDataMap dataMap = context.getMergedJobDataMap();
   //     System.out.println("dataMap num："+dataMap.getString("num"));


        System.out.println("自动注入:"+num);

        triggerMap.put("count",triggerMap.getInt("count")+1);
        jobDataMap.put("count",jobDataMap.getInt("count")+1);

        System.out.println("triggerMap count:"+triggerMap.getInt("count"));
        System.out.println("jobDetailMap count:"+jobDataMap.getInt("count"));
        System.out.println("hello:"+ LocalDateTime.now());
    }
}
